import Vue from 'vue'
import Router from 'vue-router'
import index from ' @/components/index'
import cart from ' @/components/cart'
import item from ' @/components/item'
import detail from ' @/components/detail'
import mytest from ' @/components/mytest'
import test from ' @/components/test'
import myheader from ' @/components/myheader'
import footer from ' @/components/footer'
import register from ' @/components/register'
import login from ' @/components/login'
import myprofile from ' @/components/myprofile'
import myadmin from ' @/components/myadmin'
import add_pics from ' @/components/add_pics'
import updatepics from ' @/components/updatepics'

import add from ' @/components/add'
import add_goods from ' @/components/add_goods'
import search from " @/components/search";

Vue.use(Router)

var routes = [
  {
    path: '/',
    name: 'index',
    component: index
  },
  {
    path: '/cart',
    name: 'cart',
    component: cart
  },
  {
    path: '/item',
    name: 'item',
    component: item
  },
  {
    path: '/detail',
    name: 'detail',
    component: detail
  },
  {
    path: '/mytest',
    name: 'mytest',
    component: mytest
  },
  {
    path: '/test',
    name: 'test',
    component: test
  },
  {
    path:'/myheader',
    name:'myheader',
    component:myheader
  },
  {
    path:'/footer',
    name:'footer',
    component:footer
  },
  {
    path: '/register',
    name: 'register',
    component: register
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/myprofile',
    name: 'myprofile',
    component: myprofile
  },
  {
    path: '/add_pics',
    name: 'add_pics',
    component: add_pics
  },
  {
    path: '/updatepics',
    name: 'updatepics',
    component: updatepics
  },
  {
    path: '/index',
    name: 'index',
    component: index
  },
  {
    path: '/myadmin',
    name: 'myadmin',
    component: myadmin,
    beforeEnter: (to, from, next) => {
      // 判断用户是否登录
      if (localStorage.getItem('username')) {
        next();
      } else {
        next('/login');
      }

    }
  },
  {
    path: '/add',
    name: 'add',
    component: add
  },
  {
    path: '/add_goods',
    name: 'add_goods',
    component: add_goods
  },
  {
    path:'/search',
    name:'search',
    component: search
  },
]

export default new Router({
  routes: routes,
  mode: 'history'   /*hash*/
})
